<template>
  <div :style="style">
    <h3 v-if="title_" class="title">{{ title_ }}</h3>
    <ym-form v-model="value" v-bind="$attrs" @close="$emit('close')"/>
  </div>

</template>

<script>
import YmForm from "@/ym/components/form/YmForm";
import {TITLE, URL} from "@/store/elementui";
import { ROW, WIDTH } from '@/store/form'

/**
 * props: {
 *    url: string,
 *    ...ym-form
 * }
 */
export default {
  data () {
    return {
      title_: this[TITLE],
      value: {}
    }
  },
  computed: {
    style () {
      if (!this[WIDTH]) return {}
      let width = this[WIDTH]
      return {
        width
      }
    }
  },
  components: {
    YmForm
  },
  async created () {
    if (this[URL]) {
      const r = await this.$http.Get(this[URL])
      this.value = r[ROW] || {}
    }
  },
  props: {
    [TITLE]: {
      type: String,
      default: null
    },
    [URL]: {
      type: String,
      default: null
    },
    [WIDTH]: {
      type: String,
      default: null
    }
  }
}
</script>

<style scoped>

</style>
